import {
  Controller,
  Get,
  Param,
  ValidationPipe,
  Request,
  Post,
  UseGuards,
} from '@nestjs/common';
import { AdminAuthService, AdminService } from '../services';
import { GetJsonParamsDto } from '../dto';
import { AdminJwtAuthGuard, AdminLocalAuthGuard } from '../guards';

@Controller('admin')
export class AdminController {
  constructor(
    private readonly adminService: AdminService,
    private readonly authService: AdminAuthService,
  ) {}
  @UseGuards(AdminJwtAuthGuard)
  @Get('pages/:module/:path/:name.json')
  getJson(@Param(new ValidationPipe()) params: GetJsonParamsDto) {
    console.log(params);
    return this.adminService.getJson(params);
  }
  @UseGuards(AdminLocalAuthGuard)
  @Post('login')
  async login(@Request() req) {
    return this.authService.login(req.user);
  }
  @UseGuards(AdminJwtAuthGuard)
  @Get('checkLogin')
  checkLogin(@Request() req) {
    return { status: 0, msg: '', data: req.user };
  }
  @UseGuards(AdminJwtAuthGuard)
  @Get('user')
  getUser(@Request() req) {
    return req.user;
  }
}
